/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>			                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#include "./Color.h"

/**************************************************************
* Constructors                                                *
***************************************************************/
Color::Color(const Color& color) {
	mR = color.mR;
	mG = color.mG;
	mB = color.mB;
	mA = color.mA;
}

/**************************************************************
* Operators                                                   *
***************************************************************/
Color& Color::operator+=(const Color& color) {
	mR += color.mR;
	mG += color.mG;
	mB += color.mB;
	mA += color.mA;

	return *this;
}

Color& Color::operator-=(const Color& color) {
	mR -= color.mR;
	mG -= color.mG;
	mB -= color.mB;
	mA -= color.mA;

	return *this;
}

Color Color::operator-() const {
	return Color(-mR, -mG, -mB, -mA);
}

Color& Color::operator*=(const Color& color) {
	mR *= color.mR;
	mG *= color.mG;
	mB *= color.mB;
	mA *= color.mA;

	return *this;
}

Color& Color::operator*=(const cFloat fFactor) {
	mR *= fFactor;
	mG *= fFactor;
	mB *= fFactor;
	mA *= fFactor;

	return *this;
}

Color& Color::operator=(const Color& color) {
	mR = color.mR;
	mG = color.mG;
	mB = color.mB;
	mA = color.mA;

	return *this;
}

Color Color::operator*(const cFloat fFactor) {
	return Color(mR * fFactor, mG * fFactor, mB * fFactor, mA * fFactor);
}

/**************************************************************
* Helpful functions                                           *
***************************************************************/
inline cVoid Color::ClipComponents() {
	mR = (mR < 0.0f) ? 0.0f : (mR > 1.0f ? 1.0f : mR);
	mG = (mG < 0.0f) ? 0.0f : (mG > 1.0f ? 1.0f : mG);
	mB = (mB < 0.0f) ? 0.0f : (mB > 1.0f ? 1.0f : mB);
	mA = (mA < 0.0f) ? 0.0f : (mA > 1.0f ? 1.0f : mA);
}

inline cVoid Color::PositiveClipComponents() {
	mR = (mR > 1.0f) ? 1.0f : mR;
	mG = (mG > 1.0f) ? 1.0f : mG;
	mB = (mB > 1.0f) ? 1.0f : mB;
	mA = (mA > 1.0f) ? 1.0f : mA;
}

cWinColor Color::ToWinColor(const Color& color) {
	return RGB(color.mR * 255.0f, 
		color.mG * 255.0f, 
		color.mB * 255.0f);
}

Color Color::Red() {
	return Color(1.0f, 0.0f, 0.0f);
}

Color Color::Green() {
	return Color(0.0f, 1.0f, 0.0f);
}

Color Color::Blue() {
	return Color(0.0f, 0.0f, 1.0f);
}

Color Color::White() {
	return Color(1.0f, 1.0f, 1.0f);
}

Color Color::Black() {
	return Color(0.0f, 0.0f, 0.0f);
}